/**
 * 日期补全0
 * @param {Object} value
 */
function dateFormat(value) {
	return value < 10 ? "0" + value : value;
}

/**
 * 获取当前日期, 格式YYYY-MM-DD
 * @param {Object} days
 */
function getDate(days) {
	var date = new Date();
	date.setDate(date.getDate() + days);
	var y = date.getFullYear();
	var m = dateFormat(date.getMonth() + 1);
	var d = dateFormat(date.getDate());
	return y + "-" + m + "-" + d;
}

/**
 * 获取当前日期, 格式YYYY-MM-DD
 * @param {Object} date
 */
function getNowDate(date) {
	if (date == null) date = new Date();
	var day = date.getDate();
	var month = date.getMonth() + 1; //注意月份需要+1
	var year = date.getFullYear();
	return year + "-" + dateFormat(month) + "-" + dateFormat(day);
}

/**
 * 获取当前时间, 格式YYYY-MM-DD HH:mm:ss
 */
function getNow() {
	var date = new Date();
	var h = date.getHours();
	var m = date.getMinutes();
	var s = date.getSeconds();
	return getNowDate(date) + " " + dateFormat(h) + ":" + dateFormat(m) + ":" + dateFormat(s);
}

export {
	getDate,
	getNow
};
